/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.fonline.apps;

import javax.microedition.lcdui.Graphics;

/**
 *
 * @author Michael
 */
public class MissileList {

    private Missile root = null;

    public void add(Missile node) {
        if (root == null) {
            root = node;
            root.next = null;
        } else {
            Missile tmp = root;
            while (tmp.next != null) {
                tmp = tmp.next;
            }
            tmp.next = node;
            tmp = tmp.next;
            tmp.next = null;
        }
    }

    void update(Graphics g) {
        Missile temp = root;
        while (temp != null) {
            temp.update(g);
            temp = temp.next;
        }
    }

    void move(double time) {
        Missile temp = root;
        while (temp != null) {
            temp.move(time);
            temp = temp.next;
        }
    }

    Missile getRoot() {
        return root;
    }

    public void remove(Missile lowest) {
        Missile tmp = root;
        if (tmp == null) {
            return;
        }
        if (tmp == lowest) {
            root = tmp.next;
            return;
        } else if (tmp.next == null) {
            return;
        }

        while (tmp.next != null && tmp.next != lowest) {
            tmp = tmp.next;
        }
        if (tmp.next != null && tmp.next == lowest) {
            tmp.next = tmp.next.next;
        }
    }
}
